package app.imttf.offline.backing.validate;

import app.imttf.offline.adfextensions.ADFUtils;
import app.imttf.offline.model.OfflineTtfAMImpl;

import app.imttf.offline.model.view.validasi.CheckValLevel1CompleteViewImpl;

import app.imttf.offline.model.view.validasi.CheckValLevel2CompleteViewImpl;

import java.util.Map;

import oracle.adf.view.rich.context.AdfFacesContext;

public class CheckValidationComplete {
    public CheckValidationComplete() {
    }

    public void checkValidationLvl1() {
        AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
        Map<String, Object> pageFlowScope = adfFacesContext.getPageFlowScope();
        
        String keyTtf = (String)pageFlowScope.get("keyTtf");            
        String tipeSup = (String)pageFlowScope.get("tipeSup"); 
        
        OfflineTtfAMImpl offlineTtfAM =
               (OfflineTtfAMImpl)ADFUtils.getApplicationModuleForDataControl("OfflineTtfAMDataControl");
        
        CheckValLevel1CompleteViewImpl checkValLevel1CompleteView = offlineTtfAM.getCheckValLevel1CompleteView1();
        checkValLevel1CompleteView.setkeyTtf(keyTtf);
        checkValLevel1CompleteView.executeQuery();
        
        long checkValLevel1CompleteNumRow = checkValLevel1CompleteView.getEstimatedRowCount();
        
        if (checkValLevel1CompleteNumRow > 0) {
            if (tipeSup.equalsIgnoreCase("Y")) {
                pageFlowScope.put("ttfValid", "FPKP");
            } else {
                pageFlowScope.put("ttfValid", "FNPKP");
            }
            pageFlowScope.put("goValidate2", "N");
        } else {
            pageFlowScope.put("goValidate2", "Y");
        }
        
    }

    public void checkValidationLvl2() {
        AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
        Map<String, Object> pageFlowScope = adfFacesContext.getPageFlowScope();
        
        String keyTtf = (String)pageFlowScope.get("keyTtf");            
        String tipeSup = (String)pageFlowScope.get("tipeSup");  
        
        OfflineTtfAMImpl offlineTtfAM =
               (OfflineTtfAMImpl)ADFUtils.getApplicationModuleForDataControl("OfflineTtfAMDataControl");
        
        CheckValLevel2CompleteViewImpl checkValLevel2CompleteView = offlineTtfAM.getCheckValLevel2CompleteView1();
        checkValLevel2CompleteView.setkeyTtf(keyTtf);
        checkValLevel2CompleteView.executeQuery();
        
        long checkValLevel1CompleteNumRow = checkValLevel2CompleteView.getEstimatedRowCount();
        
        if (checkValLevel1CompleteNumRow > 0) {
            if (tipeSup.equalsIgnoreCase("Y")) {
                pageFlowScope.put("ttfValid", "FPKP");   
            } else {
                pageFlowScope.put("ttfValid", "FNPKP"); 
            }
            pageFlowScope.put("memoMd", "Y");
        } else {
            pageFlowScope.put("ttfValid", "V");
            pageFlowScope.put("memoMd", "N");
        }
    }
}
